package com.tencent.sr.iris.basic.saas.service.dependency;

import com.tencent.sr.iris.activity.interfaces.client.task.IrisOperateBoardClient;
import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.OperateBoardThirdRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.UnJoinTaskRequest;
import com.tencent.sr.iris.activity.interfaces.response.group.AdvisorBoardResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.GroupTaskPaginationResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.operate.*;
import com.tencent.sr.iris.basic.saas.common.enums.TaskTargetEvaluationEnum;
import com.tencent.sr.iris.basic.saas.common.utils.HttpUtils;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Component
@Slf4j
public class OperateBoardDependency {
    @Resource
    private IrisOperateBoardClient operateBoardClient;

    public PaginationResponse<OperateBoardInviteResponse> operateBoardInviteExport(
            PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateBoardInvite(request).getData();
    }

    public PaginationResponse<OperateBoardSprintResponse> operateBoardSprintExport(
            PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateBoardSprint(request).getData();
    }

    public PaginationResponse<OperateBoardCommissionResponse> operateBoardCommission(
            PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateBoardCommission(request).getData();
    }

    public PaginationResponse<OperateBoardFirstOrderResponse> operateBoardFirstOrder(
            PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateFirstOrder(request).getData();
    }


    public PaginationResponse<AdvisorBoardResponse> queryOperateBoard(
            PaginationRequest<AdvisorGroupTaskRequest> request) {
        AdvisorGroupTaskRequest queryCriteria = request.getQueryCriteria();

        if (Objects.isNull(queryCriteria)) {
            queryCriteria = new AdvisorGroupTaskRequest();
            request.setQueryCriteria(queryCriteria);
        }
        List<Integer> taskTargetEvaluation = queryCriteria.getTaskTargetEvaluation();
        if (CollectionUtils.isNotEmpty(taskTargetEvaluation) &&
                taskTargetEvaluation.contains(TaskTargetEvaluationEnum.TRAINEE_LEVEL_UP.getCode())) {
            taskTargetEvaluation.add(TaskTargetEvaluationEnum.MEMBER_LEVEL_UP.getCode());
            taskTargetEvaluation.add(TaskTargetEvaluationEnum.SENIOR_LEVEL_UP.getCode());
        }
        return HttpUtils.handleResult(operateBoardClient.queryOperateBoard(request));
    }

    public GroupTaskPaginationResponse<OperateSecondBoardResponse> queryOperateSecondBoard(
            PaginationRequest<OperateBoardRequest> request) {
        return operateBoardClient.queryOperateSecondBoard(request).getData();
    }

    public PaginationResponse<OperateThirdBoardResponse> queryOperateThirdBoard(
            PaginationRequest<OperateBoardThirdRequest> request) {
        return operateBoardClient.queryOperateThirdBoard(request).getData();
    }

    public PaginationResponse<UnJoinTaskResponse> listUnJoinTaskLeader(
            PaginationRequest<UnJoinTaskRequest> request) {
        return operateBoardClient.listUnJoinTaskLeader(request).getData();
    }

}
